/**
 * set用来确认列表的值都是唯一的
 * IE11以上才能使用，但是有些方法还不支持，所以不建议使用
 * 
 */
let s=new Set([1,2]);
// add(val)
s.add(3);
//delete(val)
s.delete(2);
//size
s.size;
//has(val)
s.has(4);
//清空
s.clear()


{
    let mySet1=[1,2,["a","b"]]
    //循环
    mySet1.forEach(function(value) {
        console.log(value)
      })
    // iterate over items in set
    // logs the items in the order: 1, "some text", {"a": 1, "b": 2}, {"a": 1, "b": 2}
    for (let item of mySet1) console.log("mySet1",item)

    // logs the items in the order: 1, "some text", {"a": 1, "b": 2}, {"a": 1, "b": 2}
    for (let item of mySet1.keys()) console.log("keys",item)

    // logs the items in the order: 1, "some text", {"a": 1, "b": 2}, {"a": 1, "b": 2}
    for (let item of mySet1.values()) console.log("val",item)

    // logs the items in the order: 1, "some text", {"a": 1, "b": 2}, {"a": 1, "b": 2}
    // (key and value are the same here)
    for (let [key, value] of mySet1.entries()) console.log("entries",key,value)  
}

{
    let mySet1=[1,2,["a","b"]]
    //把set转成arr
const myArr = Array.from(mySet1) // [1, "some text", {"a": 1, "b": 2}, {"a": 1, "b": 2}]
}
console.assert("hellwo"=="hellw1o");


{
    let mySet1=[1,2,["a","b"]];
    let mySet2=new Set([1,2,["a","b"],4,3]);
    
// intersect can be simulated via
const intersection = new Set([...mySet1].filter(x => mySet2.has(x)))

// difference can be simulated via
const difference = new Set([...mySet1].filter(x => !mySet2.has(x)))
}


